package com.xiongmingzhu.controller;

import com.xiongmingzhu.entity.Student;
import com.xiongmingzhu.entity.StudentClass;
import com.xiongmingzhu.service.StudentService;
import com.xiongmingzhu.util.PageResult;
import com.xiongmingzhu.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/student")
@CrossOrigin
public class StudentController {
    @Autowired
    private StudentService studentService;
    @PostMapping("/loadList")
    public PageResult<Student> loadList(Integer pageNo, Integer pageSize, @RequestBody Student searchStudent){
        return  studentService.loadList(pageNo,pageSize,searchStudent);
    }
    @GetMapping("/loadAllClass")
    public List<StudentClass> loadAllClass(){
        return  studentService.loadAllClass();
    }
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student){
        int i = studentService.addStudent(student);
        if(i > 0) return Result.success("add成功！");
        return Result.error("add失败！");
    }

}
